#include "cnrandom.h"

void cnRandomInit()
{
    srand(time(NULL));
};

char cnRandomDice()
{
    return (rand() % 6) + 1;
};

char *cnRandomPattern(int size)
{
    char *ret = new char[size];
    int used[6];
    int max = size / 6;
    int color;
    int c;
    for (int i = 0; i < 6; i++) used[i] = 0;
    for (int i = 0; i < size; i++)
    {
        color = rand() % 6;
        if (used[color] == max)
        {
            c = max;
            for (int j = 0; j < 6; j++)
                if (used[j] < c)
                {
                    c = used[j];
                    color = j;
                }
        }
        ret[i] = color + 1;
        used[color]++;
    }
    return ret;
};
